package cn.elwy.rcp.kit.builder.ams;

import java.io.File;
import java.io.IOException;

import cn.elwy.common.util.VersionUtil;
import cn.elwy.common.util.io.FileUtil;

public class CopyLib {

	public static void main(String[] args) {
		String root = "E:/Workspace/ysstech/AMS/YSSUCO_V1.20.4.7_YWDEV/server/";

		FileUtil.deleteFile(new File(root, "source/com.yss.uco.bridge/work"));
		FileUtil.deleteFile(new File(root, "source/YSS_APP/com.yss.uco.deployment"));

		File[] listFiles = new File(root, "plugins").listFiles();

		String msg = "source/com.yss.messagecenter/WebRoot/WEB-INF/lib";
		String platform = "source/com.yss.platform/WebRoot/WEB-INF/lib";
		String bridge = "source/com.yss.uco.bridge/WebRoot/WEB-INF/plugins";
		String YssPeripheral = "source/YssPeripheral/WebRoot/WEB-INF/lib";
		for (File file : listFiles) {
			copyLib1(root, bridge, file, file.getName());

			String name = VersionUtil.getFileName(file.getName());
			copyLib(root, msg, file, name);
			copyLib(root, platform, file, name);
			copyLib(root, YssPeripheral, file, name);
		}

	}

	private static void copyLib1(String root, String path, File file, String name) {
		File[] listFiles = new File(root, path).listFiles();
		for (File file2 : listFiles) {
			if (name.equalsIgnoreCase(file2.getName())) {
				try {
					FileUtil.deleteFile(file2);
					FileUtil.copyFile(file, file2, true);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	private static void copyLib(String root, String path, File file, String name) {
		File[] listFiles = new File(root, path).listFiles();
		for (File file2 : listFiles) {
			String name2 = VersionUtil.getFileName(file2.getName());
			if (name.equalsIgnoreCase(name2)) {
				try {
					FileUtil.deleteFile(file2);
					FileUtil.copyFile(file, new File(file2.getParentFile(), name), true);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
